package com.baozhun.mall.common.decoration

import android.content.Context
import android.graphics.Rect
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zhpan.bannerview.utils.BannerUtils
import kotlin.math.ceil

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2022/11/15
 * @Version：1.0.0
 */
class ProductListItemDecoration: RecyclerView.ItemDecoration() {

    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        val layoutParams = view.layoutParams as RecyclerView.LayoutParams
        val itemPosition = layoutParams.viewLayoutPosition
        val layoutManager: GridLayoutManager = parent.layoutManager as GridLayoutManager
        val spanCount = layoutManager.spanCount
        if (itemPosition % spanCount == 0) {
            outRect.left = BannerUtils.dp2px(10f)
            outRect.right = BannerUtils.dp2px(5f)
        } else {
            outRect.left = BannerUtils.dp2px(5f)
            outRect.right = BannerUtils.dp2px(10f)
        }
    }
}